<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title></title>
</head>
<body>

</body>
<script>
    function person() {
        this.name = 'dengtao';
        this.age = 25;
        this.sayname = function () {
            alert(this.name);

        }
    }

    var p1 = new person();


    //用return代替new的返回

    function student() {
        this.name = 'yuyu';
        this.age = 18;
        this.sayhello = function () {
            alert('hello' + this.name);
        }

        return {'name': '代替return'};
    }

    var s1 = new student();


    //return返回的是否就是this

    function persons() {
        this.name = 'dengtao1';
        this.age = 25;
        this.sayname = function () {
            alert(this.name);

        }
        return this;
    }

    var p2 = new persons();
    var p3 = persons();

    //this永远指向当前正在被执行的函数或方法的owner。
    var obj = {
        aa: 'aa',
        init: function () {
            console.log(this);
        }
    }

    window.obj.init();


    function Dog() {
        this.sound = '汪汪汪';
    }
    Dog.prototype.bark = function () {
        alert(this.sound);
    }


    var cat = {sound: '喵喵喵'};


    Dog.prototype.bark.call(cat);


    //cat.apply(Dog.prototype.bark());

    /**
     *
     function dog() {
        this.sound = '汪汪汪';
        this.see = function () {
            alert(this.sound);
        }
    }

     var d1 = new dog();

     d1.sound = '汪汪汪旺旺';
     d1.see();//汪汪汪旺旺
     var d2 = new dog();//实例并不会影响原来的对象
     d2.see();//汪汪汪
     */


    /**
     function cat() {
        this.sound = '喵喵喵';
        this.see = function () {
            alert(this.sound);
        }
    }

     cat.prototype.see = function () {
        alert('prototype：' + this.sound);
    }

     cat.prototype.aa = 'aa';

     var c1 = new cat();
     c1.see();
     console.log(c1.aa);
     c1.aa='bb';
     console.log(c1.aa);
     var c2 = new cat();
     console.log(c2.aa);*/

    /**
     var aa = {
        a: 'a',
        al: function () {
            this.sound = 'mmm';
            alert(this.a);
        }
    }

     aa.al.prototype.alt = function () {
        alert(this.sound);
    }

     var asa = new aa.al();
     asa.alt();*/

</script>
</html>